package com.tjshop.android.util;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * SharedPreferencesUtil
 * 
 * @author zhenghou 2014-11-26 下午2:50:52
 */
public class SharedPreferencesUtil {
	public static void save(Context context, String spName, String name,
			String key) {
		SharedPreferences mySharedPreferences = context.getSharedPreferences(
				spName, Activity.MODE_PRIVATE);

		SharedPreferences.Editor editor = mySharedPreferences.edit();

		editor.putString(name, key);

		editor.commit();
	}

	public static String get(Context context, String spName, String name) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				spName, Activity.MODE_PRIVATE);
		return sharedPreferences.getString(name, "");
	}

	public static void remove(Context context, String spName, String name) {
		SharedPreferences mySharedPreferences = context.getSharedPreferences(
				spName, Activity.MODE_PRIVATE);

		SharedPreferences.Editor editor = mySharedPreferences.edit();

		editor.remove(name);

		editor.commit();
	}
	/**
	 * 
	 * @param context
	 * @param id
	 * @param status 0表示暂停，1表示继续播放
	 */
	public static void savePlayAudioCardIDAndStatus(Context context, String id,String status) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"audiocardid", Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPreferences.edit();// 获取编辑器
		editor.putString("id", id+"|"+status);
		editor.commit();
	}

	public static String getPlayAudioCardIDAndStatus(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"audiocardid", Context.MODE_PRIVATE);
		String name = sharedPreferences.getString("id", "");
		return name;
	}
	
	public static boolean getIsNeedSample(Context context, String user){
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"sample", Context.MODE_PRIVATE);
		boolean isNeedSample = sharedPreferences.getBoolean(user, true);
		return isNeedSample;
	}
	
	public static void setIsNeedSample(Context context ,String user, boolean isNeedSample){
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				"sample", Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPreferences.edit();// 获取编辑器
		editor.putBoolean(user, isNeedSample);
		editor.commit();
	}
}
